//
// Created by zhupi on 2024/10/19.
//

#include "plan_widget.h"
#include <QVBoxLayout>
#include <QHeaderView>

void PlanWidget::Initial() {
    QVBoxLayout *mainVbox = new QVBoxLayout;
    tableWidget_ = new QTableWidget(4, 4, this);
    mainVbox->addWidget(tableWidget_);
    this->setLayout(mainVbox);

    InitTableWidget();
}

void PlanWidget::InitTableWidget()
{
    tableWidget_->verticalHeader()->setVisible(false);  // 去除左边的序号
    tableWidget_->horizontalHeader()->setStyleSheet("background-color: #A9A9A9; font-weight: bold;");  // 设置表头浅灰色
    tableWidget_->setHorizontalHeaderLabels(QStringList() << "Name" << "Value" << "Unit" << "Evaluated...");

    QStringList nameList{ "Name", "Coordinate System", "Root Point", "Normal"};
    for (int index = 0; index < nameList.size(); index++) {
        QTableWidgetItem *item = new QTableWidgetItem(nameList.at(index));
        item->setFlags(item->flags() & ~Qt::ItemIsEditable);
        tableWidget_->setItem(index, 0, item);
    }

    NotEdit();

    // 设置所有行的高度为 24
    for (int row = 0; row < tableWidget_->rowCount(); ++row) {
        tableWidget_->setRowHeight(row, 24);
    }
}

void PlanWidget::NotEdit() {

    // 设置所有单元格不可编辑，除了特定的 Value 列
    for (int row = 0; row < tableWidget_->rowCount(); ++row) {
        for (int col = 0; col < tableWidget_->columnCount(); ++col) {
                QTableWidgetItem *item = tableWidget_->item(row, col);
                if (!item) {
                    item = new QTableWidgetItem();
                    tableWidget_->setItem(row, col, item);
                }
                item->setFlags(item->flags() & ~Qt::ItemIsEditable);
        }
    }

}
